 package com.oanda.blackberry.ui;
 
 import net.rim.device.api.ui.ContextMenu;
 import net.rim.device.api.ui.Field;
 import net.rim.device.api.ui.Font;
 import net.rim.device.api.ui.Graphics;
 import net.rim.device.api.ui.component.BasicEditField;
 import net.rim.device.api.ui.component.EditField;
 
 public class ColoredEditField extends EditField
 {
   int fontColor;
   int titleColor = -1;
   String title;
 
   public ColoredEditField(int color)
   {
     this.fontColor = color;
   }
 
   public ColoredEditField(int color, String label) {
     super("", label);
     this.fontColor = color;
   }
 
   public ColoredEditField(int color, String title, String label) {
     super(title, label);
     this.fontColor = color;
   }
 
   public ColoredEditField(int color, String title, String text, long style) {
     super(title, text, 50, style);
     this.fontColor = color;
   }
 
   public ColoredEditField(int labelColor, int color, String title, String label, long style) {
     super(title, label, 50, style);
     this.fontColor = color;
   }
 
   public ColoredEditField(int color, String title, String text, int maxSize, long style) {
     super(title, text, maxSize, style);
     this.fontColor = color;
   }
 
   String getTextWithSameWidth(String s) {
     String t = "";
     int w = getFont().getAdvance(s);
     for (int i = 0; (s != null) && (i < w); ) {
       t = t + " ";
       i = getFont().getAdvance(t);
     }
     return t;
   }
   public ColoredEditField(int titleColor, int color, String title, String text, int maxSize, long style) {
     super("", text, maxSize, style);
     String t = getTextWithSameWidth(title);
     setLabel(t);
 
     this.title = title;
     this.fontColor = color;
     this.titleColor = titleColor;
   }
 
   public void setTitleColor(int titleColor) {
     this.titleColor = titleColor;
   }
 
   public void setFontColor(int fontColor) {
     this.fontColor = fontColor;
   }
 
   public void paint(Graphics g)
   {
     if (this.titleColor == -1) {
       this.titleColor = this.fontColor;
     }
 
     g.setColor(this.titleColor);
     g.setFont(getFont());
     if ((getLabel() != null) && (getLabel().length() > 0))
       g.drawText(getLabel(), 0, 0);
     else if (this.title != null) {
       g.drawText(this.title, 0, 0);
     }
 
     g.setColor(this.fontColor);
     super.paint(g);
   }
 
   public void setText(String text) throws IllegalArgumentException
   {
     try {
       if (text == null)
         super.setText("---");
       else if (text.length() == 0)
         super.setText("---");
       else
         super.setText(text);
     }
     catch (IllegalArgumentException ia)
     {
       super.setText("");
     }
   }
 
   protected void makeContextMenu(ContextMenu contextMenu)
   {
   }
}

